package blocos;

public class BlockActuator extends Block{
	String value;
	
	public BlockActuator(String v){
		if(v.compareToIgnoreCase("0")==0){
			value=String.valueOf(0);
		}
		else if(v.compareToIgnoreCase("1")==0){
			value=String.valueOf(1);
		}
		else{
			value="-";
		}
		
	}
	
	void attachRight (Block a ) throws DiferentsBlocks 
	{
		if ((a instanceof blocos.BlockLogic )||(a instanceof blocos.BlockWire))
		{
			
			super.attachRight(a);
		}
		else
		{
		    throw new DiferentsBlocks();
		}
	}
	
	void attachLeft (Block a ) throws DiferentsBlocks 
	{

		if ((a instanceof blocos.BlockLogic )||(a instanceof blocos.BlockWire))
		{
		
			super.attachLeft(a);
		
		}
		else
		{
		    throw new DiferentsBlocks();
		}
	}

	void attachTop (Block a ) throws DiferentsBlocks 
	{
		
		if ((a instanceof blocos.BlockLogic )||(a instanceof blocos.BlockWire))
		{
			
			this.top = a;
			this.top.bottom = this;
			
		}
		else
		{
		    throw new DiferentsBlocks();
		}
	}
	
	void attachBottom (Block a ) throws DiferentsBlocks 
	{

		if ((a instanceof blocos.BlockLogic )||(a instanceof blocos.BlockWire))
		{
			this.bottom = a;
			this.bottom.top = this;
			
		}
		else
		{
		    throw new DiferentsBlocks();
		}
	}
	void detachRight () 
	{
		
		if(this.right!=null)
		{
//			BlockLogic temp = (BlockLogic)this.right;
			super.detachRight();
//			temp.showResult();
		}
		else
		{
			super.detachRight();
		}		
	}
	
	void detachLeft () 
	{
		if(this.left!=null)
		{
//			BlockLogic temp = (BlockLogic)this.left;
			super.detachLeft();
//			temp.showResult();
		}
		else
		{
			super.detachLeft();
		}
	}
	
	
	void detachTop () 
	{
		if(this.top!=null)
		{
//			BlockLogic temp = (BlockLogic)this.top;
			super.detachTop();
//			temp.showResult();
		}
		else
		{
			super.detachTop();
		}
		
	}
	
	void detachBottom ()
	{
		if(this.bottom!=null)
		{
//			BlockLogic temp = (BlockLogic)this.bottom;
			super.detachBottom();
//			temp.showResult();
		}
		else
		{
			super.detachBottom();
		}				
	}
	
	
	//persistencia
	
	public String[] save() {
		String [] a  = new String[1];
		a[0]=this.value;
		return a ;
	}

}

